package sample;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.control.cell.TextFieldTableCell;
import javafx.stage.Stage;

import java.io.IOException;
import java.sql.SQLException;

public class Controller2 {
    public Message message = Controller.message;
//    @FXML
//    public Button mybutton;
    @FXML protected void mybutton (ActionEvent event) throws SQLException, IOException{
        ObservableList<Message> data = FXCollections.observableArrayList(message);
        //表使用的数据
        TableView<Message> table = new TableView();
        //定义表格的行标
        TableColumn name = new TableColumn("城市");
        TableColumn conNum = new TableColumn("累计确诊");
        TableColumn deathNum = new TableColumn("累计死亡");
        TableColumn cureNum = new TableColumn("累计治愈");
        TableColumn asymptomNum = new TableColumn("目前新增");
        TableColumn updateTime = new TableColumn("数据更新时间");

        //表格列宽宽度设置
        name.setMinWidth(100);
        conNum.setMinWidth(100);
        deathNum.setMinWidth(100);
        cureNum.setMinWidth(100);
        asymptomNum.setMinWidth(100);
        updateTime.setMinWidth(180);

        //确定数据导入的列
        name.setCellValueFactory(
                new PropertyValueFactory<>("name"));
        conNum.setCellValueFactory(
                new PropertyValueFactory<>("conNum"));
        deathNum.setCellValueFactory(
                new PropertyValueFactory<>("deathNum"));
        cureNum.setCellValueFactory(
                new PropertyValueFactory<>("cureNum"));
        asymptomNum.setCellValueFactory(
                new PropertyValueFactory<>("asymptomNum"));
        updateTime.setCellValueFactory(
                new PropertyValueFactory<>("updateTime"));
        //向表中导入数据
        table.setItems(data);
        table.setStyle("-fx-background-color:red");
        table.getColumns().addAll(name, conNum, deathNum, cureNum,asymptomNum,updateTime);
        System.out.println(name.getColumns());
        Scene scene = new Scene(table,680, 200);
        Stage stage1 = new Stage();
        stage1.setScene(scene);
        stage1.show();
//        procedrue.setTitle("Table View Sample");
//        procedrue.setScene(scene);
//        procedrue.show();


    }
//    @public class TableColumnDesign {
//
//        public static void flowerTableDesign(TableView tableTableView){
//            //新建表格列
//            TableColumn idColumn = new TableColumn("编号");
//            TableColumn nameColumn = new TableColumn("花束名");
//            TableColumn priceColumn = new TableColumn("价格");
//            TableColumn numColumn = new TableColumn("库存量");
//            TableColumn dayColumn = new TableColumn("存放天数");
//
//            // 设置列的最小宽度（列的宽度只能设置首选宽度或最小宽度
//            idColumn.setMinWidth(30);
//            nameColumn.setMinWidth(260);
//            priceColumn.setMinWidth(80);
//            numColumn.setMinWidth(80);
//
//
//            nameColumn.setCellFactory(TextFieldTableCell.forTableColumn());
//            priceColumn.setCellFactory(TextFieldTableCell.forTableColumn(new DoubleStringConverter()));
//            numColumn.setCellFactory(TextFieldTableCell.forTableColumn(new IntegerStringConverter()));
//            dayColumn.setCellFactory(TextFieldTableCell.forTableColumn(new IntegerStringConverter()));
//
//            // 指定列显示Flower对象某个属性的值
//            idColumn.setCellValueFactory(new PropertyValueFactory<>("id"));
//            nameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));
//            priceColumn.setCellValueFactory(new PropertyValueFactory<>("price"));
//            numColumn.setCellValueFactory(new PropertyValueFactory<>("num"));
//            dayColumn.setCellValueFactory(new PropertyValueFactory<>("day"));
//
//            //将创建的列添加进数据表格
//            tableTableView.getColumns().addAll(idColumn, nameColumn, priceColumn, numColumn, dayColumn);
//        }
    }

